home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _51A95FB10DB44439BEACBEE8C640880D < prev    next >
Encoding:
Text File  |  2004-01-06  |  3.0 KB  |  70 lines

  1.       #include "../CGVPMacro.csi"
  2.  
  3.       PS20Only
  4.  
  5.       MainInput { uniform sampler2D baseMap : register(s0),
  6.                   uniform sampler2D bumpMap : register(s1),
  7.                   uniform sampler2D glossMap : register(s2),
  8.                   uniform sampler1D iridescenceMap : register(s3),
  9.                   uniform float4 Ambient : register(c0),
  10.                   uniform float4 IridescenceScaleBias : register(c1),
  11.                   uniform float4 TranslucencyCoeff : register(c2) }
  12.       DeclarationsScript
  13.       {
  14.         OUT_T0_T1_T2_T3_T4_T5
  15.         FOUT
  16.       }
  17.       CoreScript
  18.       {
  19.         // load the decal
  20.         float4 baseColor = tex2D(baseMap, IN.Tex0.xy);
  21.         // load the bump normal
  22.         float4 vNormal = tex2D(bumpMap, IN.Tex1.xy)*2-1;
  23.         // load the gloss map
  24.         float4 glossColor = tex2D(glossMap, IN.Tex2.xy);
  25.  
  26.         // normalize post-filtered bump normals
  27.         //vNormal.xyz = normalize(vNormal.xyz);
  28.         
  29.         Ambient.xyz = float3(0.5,0.5,0.5);
  30.         
  31.         //======================//
  32.         // Compute diffuse term //
  33.         //======================//
  34.  
  35.         // Compute the color components based on the input base texture color, 
  36.         // the alpha value for the given pixel, ambient material color and orientation 
  37.         // toward the light source:
  38.         float3 Light = normalize(IN.Tex3.xyz);
  39.         float3 scatteredIllumination = saturate(dot(-vNormal.xyz, Light.xyz)) * baseColor.a * TranslucencyCoeff.x;
  40.         float3 diffuseContribution   = saturate(dot(vNormal.xyz, Light.xyz)) + Ambient.xyz;
  41.  
  42.         baseColor.xyz *= scatteredIllumination.xyz + diffuseContribution.xyz;
  43.  
  44.         float fOpacity = 1 - baseColor.a;
  45.  
  46.         // Premultiply alpha blend to avoid clamping:
  47.         baseColor.xyz = baseColor.xyz * fOpacity;
  48.  
  49.         //==================================//
  50.         // Compute Iridescence contribution //
  51.         //==================================//
  52.          
  53.         //.....................................................................................//
  54.         // Compute index into the iridescence gradient map, which consists of N*V coefficient  //
  55.         //.....................................................................................//
  56.         float3 View = IN.Tex4.xyz;
  57.         float fGradientIndex = dot( vNormal.xyz, View.xyz ) * IridescenceScaleBias.z + IridescenceScaleBias.w;
  58.          
  59.         // Load the iridescence value from the gradient map based on the indices we just computed above:
  60.         float4 iridescence = tex1D( iridescenceMap, fGradientIndex );
  61.  
  62.         // Compute the final color using this equation: N*H * Gloss * Iridescence + Diffuse
  63.         float3 Half = IN.Tex5.xyz;
  64.         float3 vGloss = glossColor.xyz * (saturate( dot( vNormal.xyz, Half.xyz )) * IridescenceScaleBias.x + IridescenceScaleBias.y);
  65.  
  66.         OUT.Color.xyz = baseColor.xyz + vGloss.xyz * iridescence.xyz;
  67.         OUT.Color.a = fOpacity;
  68.       }
  69.  
  70.